<?php


namespace App\Http\Controllers\Common\LaravelExcel;

use App\Exceptions\ValidatorException;
use App\Exports\InvoicesExport;
use App\Http\Controllers\Controller;
use App\Http\Repositories\Repository;
use App\Jobs\Email\SendMailJob;
use App\Jobs\ExportsExcelJob;
use App\Jobs\Queue;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use Maatwebsite\Excel\Facades\Excel;


class ExcelController extends Controller
{
    private $repository;
    public function __construct(Repository $repository)
    {
        $this->repository = $repository;
    }

    public function imports(Request $request)
    {//        return view('email');
        //验证规则
        $rules = [
            'excel' => 'required|file'
        ];
        //验证错误信息自定义
        $messages = [

        ];
        //验证结果 错误就抛出异常
        $validator = Validator::make($request->all(), $rules, $messages);
        if ($validator->fails()) {
            throw new ValidatorException($validator->errors()->all());
        }

        return $this->repository->imports($validator->getData());

    }

    public function exports(Request $request)
    {
        return $this->repository->exports($request->all());
    }
}
